<?php
session_start();
 
if ($_SESSION['login'] != 'true')
	header('Location:../login.html');
	
if(!@include_once('database.php')){include 'database.php';}
include 'accent.php';
include 'siteclass.php';

$tbscat = selectTb("select cote, cat from categorie order by cote");
$tablecat = new Tableau(1,"tbcategorie",array("txt","txt"));
$tablecat->__setadd(True);
$tablecat->__setdel(True);
$tablecat->__setupdate(True);
$tablecat->__add(new Ligne(array("Cote","Cat&#233;gorie")));
foreach ($tbscat as $tb)
{
	$ligne = new Ligne(array());
	foreach ($tb as $elem)
	{
		$ligne->__add(str_replace($dbaccent, $codeaccent, $elem));
	}
	$tablecat->__add($ligne);
}

$tbcatchoix = selectTb("select cat from categorie order by cote");
$selection = new Selection("catlien",array());
foreach ($tbcatchoix as $tb){
	$selection->__add(str_replace($dbaccent, $codeaccent, $tb[0]),false);
}

$tbs = selectTb("select cote, nom, lien, categorie from site order by cote");
$tablelien = new Tableau(1,"tblien",array("txt","txt","txt",$selection));
$tablelien->__setadd(True);
$tablelien->__setdel(True);
$tablelien->__setupdate(True);
$tablelien->__add(new Ligne(array("Cote","Nom","Hyperlien","Cat&#233;gorie")));
foreach ($tbs as $tb)
{
	$ligne = new Ligne(array());
	foreach ($tb as $elem)
	{
		$ligne->__add(str_replace($dbaccent, $codeaccent, $elem));
	}
	
	$tablelien->__add($ligne);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script type="text/javascript">
<?php
echo $tablelien->__getjavaval() . " ";
echo $tablecat->__getjavaval();
?>
</script>
<script src="../css/clientajax.js" type="text/javascript"></script>
<script src="../css/jquery.js" type="text/javascript"></script>
<script src="../css/table.js" type="text/javascript"></script>
<script type="text/javascript">
	function addDelMod(tb, act, val){
		var temp = "";
		if(tb == "tblien"){
			if(act == ACTION.ADD){
				temp = "action=add";
			}
			else if(act == ACTION.DELETE){
				temp = "action=del";
			}
			else{
				temp = "action=mod";
			}
			AddDelModLien(temp + "&cote=" + val[0] + "&nom=" + val[1] + "&lien=" + val[2] + "&categorie=" + val[3]);
		}
		else{
			if(act == ACTION.ADD){
				temp = "action=add";
			}
			else if(act == ACTION.DELETE){
				temp = "action=del";
			}
			else{
				temp = "action=mod";
			}
			AddDelModCat(temp + "&cote=" + val[0] + "&categorie=" + val[1]);
		}
	}
</script>
</head>
<body>
<form id="form1" name="form1" method="post" action="logout.php">
<p>Site</p><div id='divlien'>
<?php
echo $tablelien->__tostring();
echo "</div><p>Cat&eacute;gorie</p><div id='divcat'>";
echo $tablecat->__tostring();
?>
</div>
<p><input type="submit" name="Submit" value="D&eacute;connecter" /></p>
</form>
</body>
</html>